/*
Written by Best Flash Solutions, Inc  
See:
	http://www.bestflashsolutions.com
Contact me: contact@bestflashsolutions.com
*/

/**
 * Common functions
 */
package com.bestflashsolutions
{
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import mx.core.UIComponent;
		
	//
	//Common function
	//
	public class CommonUtils
	{
		public function CommonUtils()
		{
		}

		public static function log(message: String):void {
			//Application.application.txtMessage.text += message + "\n"; 
			//trace(message);
			//Alert.show(message, "D"); 
    	}
		
		//Move  object to ensure that its center point is at given position
		public static function moveObjectCenterPoint(dspObj: UIComponent, centerPoint: Point):void {
			dspObj.x = centerPoint.x - dspObj.width/2;
			dspObj.y = centerPoint.y - dspObj.height/2; 
		}

		//Resize to Height
		public static function sizeToHeight(objChild: UIComponent, container: Rectangle, percentage: Number):void
		{
			// set new width of the stage movie clip
			objChild.height = container.height; //Math.abs(videpPlayer.y - h) * 2;
			// set yscale based on ratio to keep same
			objChild.width = objChild.height * (percentage);
		}
		
		//Resize to Width
		public static function sizeToWidth(objChild: UIComponent, container: Rectangle, percentage: Number):void
		{
			// set new width of the stage movie clip
			objChild.width = container.width; //Math.abs(videpPlayer.y - h) * 2;
			// set yscale based on ratio to keep same
			objChild.height = objChild.width / (percentage);
		}
		
		//Fit container to other container
		public static function fitScale(objChild: UIComponent, container:Rectangle): void {
			if ((container.width/container.height) > (objChild.width/objChild.height)) {
				sizeToHeight(objChild, container, objChild.width/objChild.height);
			}
			else {
				sizeToWidth(objChild, container, objChild.width/objChild.height);				
			}
		}
	}
}